package com.niuxiaofa.newlaw.Fragment;

import android.widget.ImageView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Activity.BlindBoxActivity;
import com.niuxiaofa.newlaw.Base.BaseFragment;
import com.niuxiaofa.newlaw.Bean.HeatBean;
import com.niuxiaofa.newlaw.Network.MallPresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.Tools.ToActivityUtil;
import com.niuxiaofa.newlaw.adapter.MallAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * 商城
 */
public class MallFragment extends BaseFragment implements MallPresenter.interface_getHeat {


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    MallAdapter mallAdapter;

    @BindView(R.id.mh)
    ImageView mh;

    List<HeatBean.DataDTO.ActivityExchangeEntityListDTO> newsList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mall;
    }

    @Override
    public void initData() {


        mallAdapter = new MallAdapter(newsList, new MallAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });

        RecyclerViewHelp.setRecyclerHorizontal(recyclerview, 2).setAdapter(mallAdapter);

        MallPresenter.getHeat(this);

        mh.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(BlindBoxActivity.class);
        });

    }


    @Override
    public void getResponse(HeatBean u) {

        if (u.getCode() == 1) {

            newsList.addAll(u.getData().getActivityExchangeEntityList());

            mallAdapter.notifyDataSetChanged();
        }
    }
}
